//
//  PIcView.swift
//  颖姐姐
//
//  Created by wu on 2017/7/5.
//  Copyright © 2017年 wu. All rights reserved.
//

import UIKit

class PIcView: UIView {

    var model :[picModel]?{
        didSet{
            
            guard let m = model else{
                return
            }
            for v in subviews {
                v.isHidden = true
            }
            for index in 0..<m.count{
                let iv = subviews[index] as! UIImageView
                iv.y_setImage(urlString:m[index].key , placeholder: #imageLiteral(resourceName: "aa"))
                iv.isHidden = false
                iv.clipsToBounds = true
            }
            
        }
    }
    override func awakeFromNib() {
        super.awakeFromNib()
        setupUI()
    }
}
fileprivate extension PIcView{
    func setupUI(){
        
        let margin:CGFloat = 5
        let w = (UIScreen.main.bounds.width - 30 - margin * 2) / 3
        
        for index in 0..<9 {
            let iv = UIImageView()
            addSubview(iv)
            let col = CGFloat(index % 3)
            let row:CGFloat = CGFloat(index / 3)
            
            iv.frame = CGRect(x: col * (w + margin), y: row * (w + margin), width: w, height: w)
            iv.contentMode = .scaleAspectFill
        
            iv.clipsToBounds = true
        }
    }
}
